package net.sourceforge.jweb.jstl.easyui;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import net.sourceforge.jweb.annotation.Tag;

@Tag(name = "jstlwriter", description = "jstl writer to write content at end of page")
public class JstlWriterTag extends SimpleTagSupport implements Constants {

	@SuppressWarnings("unchecked")
	@Override
	public void doTag() throws JspException, IOException {
		List<String> lazyContentList = new ArrayList<>();
		Object obj = ((PageContext) getJspContext()).getRequest().getAttribute(KEY_LAZY_WRITE);
		if (obj != null) {
			lazyContentList = (List<String>) obj;
		}
		for (String content : lazyContentList) {
			this.getJspContext().getOut().print(content);
		}
		this.getJspContext().getOut().flush();
		super.doTag();
	}
}
